package com.open.capacity.reimburse.controller;

import java.util.List;
import java.util.Map;

import com.open.capacity.commons.Result;
import com.open.capacity.reimburse.entity.BasePayItemForm;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import com.open.capacity.reimburse.entity.BasePayItemAttach;
import com.open.capacity.reimburse.service.BasePayItemAttachService;

import com.open.capacity.commons.PageResult;

import javax.validation.Valid;

/**
 * 支出事项-附件清单
 *
 * @author
 * @email
 * @date 2023-11-23 15:47:42
 */
@RestController
@RequestMapping("basepayitemattachs")
@Api(tags = "支出事项-附件清单")
public class BasePayItemAttachController {

    @Autowired
    private BasePayItemAttachService basePayItemAttachService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('base_pay_item_attach:basepayitemattach:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = basePayItemAttachService.pageAll(params);
        return pageResult;
    }

    /**
     * 列表
     */
    @RequestMapping("/findByPayitemId")
    @PreAuthorize("hasAnyAuthority('base_pay_item_attach:basepayitemattach:list')")
    public Result findByPayitemId(String payitemId, String category) {
        List<BasePayItemAttach> list = basePayItemAttachService.findByPayitemId(payitemId, category);
        return Result.succeed(list, "success");
    }

    /**
     * 列表
     */
    @RequestMapping("/findByPayitemIds")
    @PreAuthorize("hasAnyAuthority('base_pay_item_attach:basepayitemattach:list')")
    public Result findByPayitemIds(String payitemIds, String category) {
        List<BasePayItemAttach> list = basePayItemAttachService.findByPayitemIds(payitemIds, category);
        return Result.succeed(list, "success");
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findById")
    @PreAuthorize("hasAnyAuthority('base_pay_item_attach:basepayitemattach:list')")
    public Result findById(String id) {
        return Result.succeed(basePayItemAttachService.findById(id));
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('base_pay_item_attach:basepayitemattach:save')")
    public Result save(@RequestBody @Valid BasePayItemAttach basePayItemAttach, String keyValue) {
        if (StringUtils.isEmpty(keyValue)) {
            basePayItemAttachService.save(basePayItemAttach);
        } else {
            basePayItemAttach.setId(keyValue);
            basePayItemAttachService.update(basePayItemAttach);
        }
        return Result.succeed("保存成功");
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('base_pay_item_attach:basepayitemattach:delete')")
    public Result delete(@PathVariable String id) {
        basePayItemAttachService.delete(id);
        return Result.succeed("删除成功");
    }

}
